package demo;

import java.net.InetAddress;
import java.net.UnknownHostException;
public class demo1 {
    public static void main(String[] args) throws UnknownHostException {
        //获取本机的 IP 对象
        InetAddress address = InetAddress.getLocalHost();
        //通过IP地址对象来获取到主机名称
        String name = address.getHostName();
        System.out.println(name);
    }
}
